package org.springframework.amqp.tutorials.rabbitmq_topics.runner;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.TimeUnit;

public class TopicsCommandLineRunner implements CommandLineRunner {

    @Value("${tut5.client.duration}")
    private int duration;
    @Autowired
    private ConfigurableApplicationContext context;

    @Override
    public void run(String... args) throws Exception {
        System.out.println("This app has started, and will close in " + duration + " s");
        TimeUnit.SECONDS.sleep(duration);
        context.close();
        System.out.println("Closed.");
    }
}
